home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC14FontReport / FontReport.c < prev    next >
Encoding:
Text File  |  1990-06-24  |  62.3 KB  |  1,201 lines  |  [TEXT/pdos]

  1. /* ************************************************************************* */
  2. /*                                                                           */
  3. /* Font Manager Sample Program                                               */
  4. /*                                                                           */
  5. /* Description: Produces and displays catalog of fonts on disk, shows        */
  6. /*              font strike of selected font.                                */
  7. /*                                                                           */
  8. /* Developer Technical Support Apple II Sample Code                          */
  9. /*                                                                           */
  10. /* By: Dan Strnad                                                            */
  11. /*                                                                           */
  12. /*      v3.0    Strnad                                                       */
  13. /*                                                                           */
  14. /* ShowFont Procedure adapted from HodgePodge example program                */
  15. /*                                                                           */
  16. /* Copyright 1989-1990 Apple Computer, Inc.                                  */
  17. /*                                                                           */
  18. /* ************************************************************************* */
  19.  
  20.  
  21. /* ************************************************************************* */
  22. /*                                                                           */
  23. /* General Remarks                                                           */
  24. /*                                                                           */
  25. /* Most applications need not use each of the Font Manager calls             */
  26. /* demonstrated in this program. Besides starting up and shutting down the   */
  27. /* font manager, ChooseFont and GetFamNum are the calls most programmers may */
  28. /* find use for.  QuickDraw II also provides routines and documentation for  */
  29. /* both basic and advanced handling of fonts.                                */
  30. /*                                                                           */
  31. /* Because memory management strategies differ across applications, no       */
  32. /* special provision is made in this program for handling memory error       */
  33. /* conditions such as an unable to allocate memory block error ($0201).      */
  34. /* This or other memory manager errors can be returned by several of the     */
  35. /* font manager calls. This sample program is incomplete with regard to      */
  36. /* handling of these errors, which will cause an error message to be         */
  37. /* displayed and the program to abort.  Commercial applications should       */
  38. /* differ from this sample program by more carefully handling potentially    */
  39. /* tight memory conditions.                                                  */
  40. /*                                                                           */
  41. /* Also to do with memory management, when fonts are to be marked purgeable  */
  42. /* using SetPurgeStat, the id of the font to purge should be that returned   */
  43. /* from a font manager call, such as FMGetCurFID, FindFontStats,             */
  44. /* or LoadFont.                                                              */
  45. /*                                                                           */
  46. /* The following statements contradict and supercede related information     */
  47. /* about font family numbers in the 1988 Apple IIGS Toolbox Reference        */
  48. /* Manual.  Always determine the famNum part of a font id using font manager */
  49. /* calls.  The family number for a font family known by a particular name    */
  50. /* may differ each time the font manager is started!  Do not use statements  */
  51. /* like 'MyFontID.famNum = 22;' to select the Courier font family,           */
  52. /* for instance.                                                             */
  53. /*                                                                           */
  54. /* Use GetFamNum to determine the font family number for a particularly      */
  55. /* named font family. See the AddApFont routine for an example of calling    */
  56. /* GetFamNum.                                                                */
  57. /*                                                                           */
  58. /* ************************************************************************  */
  59.  
  60.  
  61. #include <types.h>     
  62. #include <prodos.h>                             
  63. #include <misctool.h>                            
  64. #include <quickdraw.h>                         
  65. #include <window.h>
  66. #include <memory.h>
  67. #include <dialog.h>
  68. #include <menu.h>
  69. #include <control.h>
  70. #include <desk.h>
  71. #include <event.h>
  72. #include <lineedit.h>
  73. #include <misctool.h>
  74. #include <locator.h>
  75. #include <Stdfile.h>
  76. #include <qdaux.h>
  77. #include <print.h>
  78. #include <font.h>
  79. #include <intmath.h>
  80. #include <scrap.h>
  81. #include <texttool.h>
  82. #include <list.h>
  83. #include <Math.h>
  84. #include <Resources.h>
  85.  
  86. extern int _toolErr;
  87.  
  88.  
  89. /* ************************************************************************* */
  90. /*                                                                           */
  91. /* Standard Global data here                                                 */
  92. /*                                                                           */
  93. /* ************************************************************************* */
  94.  
  95. #define ScreenWidth 640
  96.  
  97. int MyID;
  98. int ThisMode = mode640;                           /* init mode = 640 */
  99.  
  100. Ref initRef;                        /* This holds the reference to the startstop record */
  101.  
  102. int QuitFlag;
  103. QuitRec QuitParms = {
  104.         NULL,                       /* Pathname of the next application */
  105.         0};                         /* Quit Flags */
  106.         
  107. WmTaskRec EventRec = {              /* Data block to hold event records */
  108.         0,
  109.         0L,
  110.         0L,
  111.         0,0,
  112.         0,
  113.         0L,
  114.         0x0000FFFFL};               /* Let TaskMaster do it all! */
  115.  
  116.  
  117. /* ************************************************************************* */
  118. /*                                                                           */
  119. /* ErrorCheck - Called from InitTools to check for startup errors.           */
  120. /*                                                                           */
  121. /* ************************************************************************* */
  122.  
  123. char DeathMsg[] = "Fatal error $0000 has occurred at 0000. Press any key to exit:";
  124.  
  125. void ErrorCheck(where)
  126.     int where;
  127. {
  128.       /* if (false) */
  129.       if (_toolErr) {
  130.        Int2Hex(_toolErr,DeathMsg + 13 ,4);  /* Stick error # into a string */
  131.        Int2Hex(where,DeathMsg + 34 ,4);     /* Stick location # into a string */
  132.        GrafOff();                           /* Turn off Super Hires */
  133.        WriteCString(DeathMsg);              /* Print the error message */
  134.        ReadChar(0);                         /* Pause for a character */
  135.        ShutDownTools(refIsHandle, initRef); /* Let the toolbox shutdown the tools. */
  136.        exit(1);                             /* exit */
  137.      }
  138. }
  139.  
  140.  
  141. /* ************************************************************************* */
  142. /*                                                                           */
  143. /* ApErrorCheck - Called to check for tool and other miscellaneous errors.   */
  144. /*                                                                           */
  145. /* ************************************************************************* */
  146.  
  147. char ApErrMsg[] = "Appl. error $0000 has occurred at 0000. Press any key to exit:";
  148.  
  149. void ApErrorCheck(where)
  150.     int where;
  151. {
  152.      int My_toolErr;
  153.      My_toolErr = _toolErr;
  154.      if (_toolErr) {
  155.        Int2Hex(_toolErr,ApErrMsg + 13 ,4);  /* Stick error # into a string */
  156.        Int2Hex(where,ApErrMsg + 34 ,4);     /* Stick location # into a string */
  157.        GrafOff();                           /* Turn off Super Hires */
  158.        WriteCString(ApErrMsg);              /* Print the error message */
  159.        ReadChar(0);                         /* Pause for a character */
  160.        if ((My_toolErr & 0xff00) == 0x200 ) /* abort sample application if memory manager error */
  161.        {
  162.             ShutDownTools(refIsHandle, initRef);    /* Let the toolbox shutdown the tools. */
  163.             exit(1);                                /* exit */
  164.        }
  165.        GrafOn();                            /* Turn on Super Hires */
  166.      }
  167. }
  168.  
  169.  
  170. /* ************************************************************************* */
  171. /*                                                                           */
  172. /* Application specific data appears here                                    */
  173. /*                                                                           */
  174. /* ************************************************************************* */
  175.  
  176. #define TLStartErr                      1
  177. #define ShowFontInstallFontErr          2
  178. #define MyDrawLoadSysFontErr            3
  179. #define MyDraw2LoadSysFontErr           4
  180. #define ApFontNewHandleErr              5
  181. #define ApFontAddFamilyErr              6
  182. #define ApFontAddFontVarErr             7
  183. #define ApFontInstallFontErr1           8
  184. #define ApFontInstallFontErr2           9
  185. #define InvFontLoadSysFontErr           10
  186. #define InvFontLoadFontErr              11
  187. #define InvFontSetPurgeStatErr          12
  188. #define DispNewFontInstallFontErr       13
  189. #define FindAltSysFontFMSetSysFontErr   14
  190. #define MenuFontChooseErr               15
  191. #define InitAppInstallFontErr           16
  192.  
  193. #define NumExampleLines 5                   /* used by ShowFont */
  194. #define NumStrikeLines 8                    /* used by ShowFont */
  195. #define ScalingOn   0                       /* used calling InstallFont */
  196. #define IllegalFontFamNum 0xffff            /* used by AddApFont */
  197. #define Hex 16                              /* used calling DrawCatInt2Base */
  198. #define Dec 10                              /* used calling DrawCatInt2Base */
  199. #define signednum true                      /* used calling DrawCatInt2Base */
  200. #define loadfonts true                      /* used calling InventoryFonts */
  201. #define dontloadfonts false                 /* used calling InventoryFonts */
  202. #define douncheck true                      /* used calling FontCheckMItem */
  203. #define omituncheck false                   /* used calling FontCheckMItem */
  204.  
  205. #define CatalogWindowID     0x1000L
  206. #define StrikeWindowID      0x1001L
  207.  
  208. /* *************************************************************************  */
  209. /*
  210. /* This sample program uses menu items that start at 250. The Edit menu items */
  211. /* if they were present would be entered first to conform to the menu manager */
  212. /* documentation. The About and Quit menu items use IDs 256 and 257 as a      */
  213. /* convention.                                                                */
  214. /*                                                                            */
  215. /* *************************************************************************  */
  216.  
  217. #define AppleMenuID         0x1100
  218. #define AboutID             0x1101
  219. #define FileMenuID          0x1200
  220. #define OpenCatWindowID     0x1201
  221. #define OpenStrikeWindowID  0x1202
  222. #define QuitID              257
  223. #define FontMenuID          0x1300
  224. #define ChooseID            0x1301
  225.  
  226.  
  227. int CurrHeight,LineCounter;
  228.  
  229. char Line0[30] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  /*   Namelength + 1  */
  230.                   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* + 4 for size info */
  231. char Line1[] = "\0";
  232. char Line2[] = "\54The quick brown fox jumps over the lazy dog.";
  233. char Line3[] = "\53She sells sea shells down by the sea shore.";
  234. char Line4[] = "\0";
  235.  
  236. char FontStrikeLine[] = {32,
  237.                  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
  238.                 16,17,18,19,20,21,22,23,24,25,25,27,28,28,30,31,0};
  239.  
  240.  
  241. char *LineTable[] = {Line0,Line1,Line2,Line3,Line4};
  242.  
  243. char __dataBank;
  244.  
  245. ptr myApFontNamePtr;
  246.  
  247. Point CurrPos;
  248.  
  249. FontID curSysID;
  250.  
  251. FontID FontToShow;
  252.  
  253. FontID ChosenFont;
  254.  
  255. int ChosenSize;
  256.  
  257. int ChosenStyle;
  258.  
  259. int checkedID;
  260.  
  261. int MyFamSpecBits;
  262.  
  263. struct FontStatRecList{
  264.     int numFontsAvail;
  265.     int numFamsAvail;
  266.     FontStatRec FontStatRecTable[200];
  267.     } FontsAvail;
  268.  
  269. int linetodraw;                             /* shared by each window's content def proc */
  270.  
  271. GrafPortPtr CatalogWindow;                   /* current window handle  */
  272. GrafPortPtr StrikeWindow;                    /* current window handle  */
  273.  
  274.  
  275. /* ************************************************************************* */
  276. /* Our sample programs use menus that start at 250. The Edit menu items are  */
  277. /* entered first to conform to the menu manager documentation. The About     */
  278. /* and Quit menu items use IDs 256 and 257 as a convention.                  */
  279. /*                                                                           */
  280. /* ************************************************************************* */
  281.  
  282.  
  283. int numFontMenuItems; /* set to number of items in font menu, after FixFontMenu is called */
  284.  
  285.  
  286. char **y,*z;            /* ZPHandle and ZPPointer */
  287.  
  288.  
  289. /* ************************************************************************* */
  290. /*                                                                           */
  291. /* This is the core of the program. It simply calls all the other routines   */
  292. /* in order.                                                                 */
  293. /*                                                                           */
  294. /* ************************************************************************* */
  295.  
  296. main()
  297. {
  298.  
  299.     /* Startup the tools using the new toolbox call */
  300.     MyID = MMStartUp();
  301.     initRef = StartUpTools(MyID, refIsResource, 0x0001L);
  302.     ApErrorCheck(TLStartErr);   /* Is StartUpTools OK? */
  303.     if (!_toolErr) {
  304.         InitApp();              /* initialize application specific stuff */
  305.         EventLoop();            /* do your stuff */
  306.     }
  307.     ShutDownTools(refIsHandle, initRef);    /* Let the toolbox shutdown the tools. */
  308. }
  309.  
  310.  
  311. /* ********************************************************************************* */
  312. /*                                                                                   */
  313. /* Assembly Procedure SaveDB:                                                        */
  314. /*                                                                                   */
  315. /* Decsription: saves data bank register and changes to data bank for globals        */
  316. /*                                                                                   */
  317. /* Inputs:  none                                                                     */
  318. /*                                                                                   */
  319. /* Outputs: data bank register contents                                              */
  320. /*                                                                                   */
  321. /* ********************************************************************************* */
  322.  
  323. asm(SaveDB) {
  324.              phb
  325.              lda  #^__dataBank   ; high word of anything in ~globals will do
  326.              pha
  327.              plb
  328.              pla
  329.  
  330.              rtl
  331. }
  332.  
  333. /* ********************************************************************************* */
  334. /*                                                                                   */
  335. /* Assembly Procedure RestoreDB:                                                     */
  336. /*                                                                                   */
  337. /* Decsription: restores data bank register                                          */
  338. /*                                                                                   */
  339. /* Inputs:  integer value to set data bank register to                               */
  340. /*                                                                                   */
  341. /* Outputs: changed data bank register                                               */
  342. /*                                                                                   */
  343. /* ********************************************************************************* */
  344.  
  345. asm(RestoreDB) {
  346.              lda  4,s
  347.              pha
  348.              plb
  349.              plb
  350.              rtl
  351. }
  352.  
  353. /* ********************************************************************************* */
  354. /*                                                                                   */
  355. /* Procedure CalcLineHeight:                                                         */
  356. /*                                                                                   */
  357. /* Decsription: calculates heigth of the text line(s) to be drawn                    */
  358. /*                                                                                   */
  359. /* Inputs:  none                                                                     */
  360. /*                                                                                   */
  361. /* Outputs: heigth of the line(s) to be drawn                                        */
  362. /*                                                                                   */
  363. /* ********************************************************************************* */
  364.  
  365. CalcLineHeight()
  366. {
  367.     FontInfoRecord CurrFont;
  368.     int LineHeight;
  369.     
  370.     GetFontInfo(&CurrFont);                                 /* prepare to compute height using */
  371.                                                             /* QuickDraw II GetFontInfo call */
  372.                                                             /* i.e. # pixels between lines drawn */
  373.     LineHeight = CurrFont.ascent + CurrFont.descent + CurrFont.leading;
  374.     return(LineHeight);
  375.  
  376. }
  377.  
  378.  
  379. /* ********************************************************************************* */
  380. /*                                                                                   */
  381. /* Procedure ShowFont:                                                               */
  382. /*                                                                                   */
  383. /* Decsription: displays fontstrike, excerpted from HodgePodge example program       */
  384. /*                                                                                   */
  385. /* Inputs:  fontID                                                                   */
  386. /*                                                                                   */
  387. /* Outputs: none                                                                     */
  388. /*                                                                                   */
  389. /* ********************************************************************************* */
  390.  
  391. ShowFont(fontId)
  392.  
  393. FontID fontId;
  394. {
  395.  
  396. #define columnone       4
  397.  
  398.    int stringpos;                                           /* loops through ASCII values   */
  399.    
  400.    InstallFont(fontId,ScalingOn);                           /* Install with scaling enabled */
  401.    ApErrorCheck(ShowFontInstallFontErr);                    /* Is InstallFont OK? */
  402.    CurrHeight = CalcLineHeight();                           /* calculate # pixels between lines */
  403.  
  404.    GetFamInfo(fontId.fidRec.famNum,Line0);                          /* set up font name, ignore result */
  405.    Int2Dec(fontId.fidRec.fontSize,                                  /* set up font size after font name */
  406.                (Line0)+Line0[0]+1,                          /* pointer to end */
  407.                4,                                           /* length of result */
  408.                0);                                          /* not signed */
  409.    Line0[0] +=4;                                            /* new length */
  410.    linetodraw = linetodraw + 15;
  411.    
  412.    for (LineCounter = 0;LineCounter < NumExampleLines;LineCounter++) {
  413.        linetodraw = linetodraw + CurrHeight;
  414.        MoveTo(columnone,linetodraw);                        /* move to beginning of line to draw */
  415.        DrawString(LineTable[LineCounter]);
  416.      }
  417.    for (LineCounter = 0;LineCounter < NumStrikeLines;LineCounter++) {
  418.        linetodraw = linetodraw + CurrHeight;
  419.        MoveTo(columnone,linetodraw);                        /* set position to Draw */
  420.        for (stringpos = 1;stringpos < 33;stringpos++) {
  421.            FontStrikeLine[stringpos] = (char) (LineCounter*32+stringpos-1);
  422.            }
  423.        DrawString(FontStrikeLine);
  424.      }
  425.     linetodraw = 0;
  426.     MoveTo(columnone,0);
  427. }
  428.  
  429.  
  430. /* ********************************************************************************* */
  431. /*                                                                                   */
  432. /* Procedure DrawCatInt2Base:                                                        */
  433. /*                                                                                   */
  434. /* Decsription: displays number and string                                           */
  435. /*                                                                                   */
  436. /* Inputs:  number to draw, base of number, number of places to display              */
  437. /*          signed number indicator, append string                                   */
  438. /*                                                                                   */
  439. /* Outputs: none                                                                     */
  440. /*                                                                                   */
  441. /* ********************************************************************************* */
  442.  
  443. DrawCatInt2Base(num,base,numplaces,signedval,catstr)
  444.  
  445. int num;                                                /* number to draw */
  446. int base;                                               /* base of number */
  447. int numplaces;                                          /* number of places to display */
  448. int signedval;                                          /* signed number indicator */
  449. char catstr[80];                                        /* append string */
  450.  
  451. {
  452.     char strtarg[80];                                   /* convert number into this string */
  453.     ptr catstrptr;                                      /* ptr to append string */
  454.     ptr strtargptr;                                     /* ptr to convert string */
  455.     
  456.     catstrptr = &catstr[0];                                 /* set the pointers */
  457.     strtargptr = &strtarg[0];
  458.     switch(base) {                                          /* do the conversion */
  459.             case Dec:
  460.                 Int2Dec(num,strtargptr,numplaces,signedval);
  461.                 break;
  462.             case Hex:
  463.                 Int2Hex(num,strtargptr,numplaces);
  464.                 break;
  465.             default:
  466.                 /* error */
  467.                 break;
  468.     }
  469.     
  470.     strtarg[numplaces]= '\0';                               /* terminate the string */
  471.     strcat(strtargptr,catstrptr);                           /* append designated string */
  472.     DrawCString(strtarg);                                   /* display result */
  473. }
  474.  
  475.  
  476. /* ********************************************************************************* */
  477. /*                                                                                   */
  478. /* Procedure MyDraw:                                                                 */
  479. /*                                                                                   */
  480. /* Decsription: window content definition procedure                                  */
  481. /*                                                                                   */
  482. /* Inputs:  none                                                                     */
  483. /*                                                                                   */
  484. /* Outputs: none                                                                     */
  485. /*                                                                                   */
  486. /* ********************************************************************************* */
  487.  
  488. MyDraw()                                                /* window content definition procedure */   
  489.  
  490. {
  491.     /* #define columnone        4 */
  492.     #define famNumbercolumn     34*6+columnone
  493.     #define fontSizecolumn      54*6+columnone
  494.     #define fontStylecolumn     68*6+columnone
  495.     char stritem1[80],stritem2[80],stritem3[80],stritem4[80];       /* string declarations */
  496.     char stritem5[80],stritem6[80],stritem7[80];
  497.     ptr strptr1,strptr2,strptr3,strptr4;                            /* string ptr declarations */
  498.     char TableTitle[80];                                            /* title string */
  499.     int eachfontavail;                                              /* index into font catalog */
  500.     int preservefontavail;                                          /* holds index temporarily */
  501.     FontStatRecPtr MyFontStatRecPtr;                                /* ptr to font status record */
  502.     FontStatRecPtr PreserveFStatRecPtr;                             /* holds ptr temporarily */
  503.     int curfamily;                                                  /* tracks font families */
  504.     int MyFamStatBits;                                              /* FamStatBits */
  505.     int dbr;                                                        /* data bank register value */
  506.     
  507.     dbr = SaveDB();                                                 /* make the data bank reg. */
  508.                                                                     /* point to globals, save it */
  509.     
  510.     strptr1 = &stritem1[0];
  511.     strptr2 = &stritem2[0];
  512.     strptr3 = &stritem3[0];
  513.     strptr4 = &stritem4[0];
  514.     strcpy(TableTitle,"\pReport of available fonts:");
  515.     LoadSysFont();                                                  /* use sys font */
  516.     ApErrorCheck(MyDrawLoadSysFontErr);                             /* Is LoadSysFont OK? */
  517.     strcpy(stritem5," fonts available, ");                          /* append strings */
  518.     strcpy(stritem6," families");
  519.     strcpy(stritem7,"");
  520.     MoveTo(columnone,50);
  521.     DrawString(TableTitle);
  522.     DrawCatInt2Base(FontsAvail.numFontsAvail,Dec,4,signednum," fonts available, ");
  523.     DrawCatInt2Base(FontsAvail.numFamsAvail,Dec,4,signednum,stritem6);
  524.     
  525.     curfamily = 0xffff;                                                     /* init current family */
  526.     strcpy(stritem1," ");                                                   /* init strings */
  527.     strcpy(stritem2," ");
  528.     strcpy(stritem3," ");
  529.     strcpy(stritem4," ");
  530.     eachfontavail = 0;
  531.     linetodraw = 50;
  532.     /*               012345678901234567890123456789012345678901234567890123456789012345678901234567 */
  533.     strcpy(stritem2,"Font family name                  family number       font size     font style");
  534.     linetodraw = linetodraw+30;
  535.     MoveTo(columnone,linetodraw);
  536.     DrawCString(stritem2);
  537.     do {                                                                /* loop through fonts */
  538.             MyFontStatRecPtr = &FontsAvail.FontStatRecTable[eachfontavail]; /* set pointer */
  539.             strcpy(stritem2," ");                                           /* init strings */
  540.             strcpy(stritem3," ");
  541.             strcpy(stritem4," ");
  542.             linetodraw = linetodraw+10;
  543.             if (MyFontStatRecPtr->resultID.fidRec.famNum != curfamily) {    /* next family? */
  544.                                                                             /* yes- display */
  545.                 MyFamStatBits = GetFamInfo(MyFontStatRecPtr->resultID.fidRec.famNum,strptr1);
  546.                 MoveTo(columnone,linetodraw);
  547.                 DrawString(stritem1);
  548.                 MoveTo(famNumbercolumn,linetodraw);
  549.                 DrawCatInt2Base(MyFontStatRecPtr->resultID.fidRec.famNum,Hex,4,signednum,stritem7);
  550.             }
  551.                                                                        /* display size and style */
  552.             curfamily = MyFontStatRecPtr->resultID.fidRec.famNum;
  553.             MoveTo(fontSizecolumn,linetodraw);
  554.             DrawCatInt2Base(MyFontStatRecPtr->resultID.fidRec.fontSize,Dec,5,signednum,stritem7);
  555.             MoveTo(fontStylecolumn,linetodraw);
  556.             DrawCatInt2Base(MyFontStatRecPtr->resultID.fidRec.fontStyle,Dec,5,signednum,stritem7);
  557.             
  558.             ++eachfontavail;
  559.     }
  560.     while (eachfontavail < FontsAvail.numFontsAvail);
  561.     RestoreDB(dbr);                                         /* restore data bank reg. for return */
  562.                                                             /* to toolbox */
  563. }
  564.  
  565.  
  566. /* ********************************************************************************* */
  567. /*                                                                                   */
  568. /* Procedure MyDraw2:                                                                */
  569. /*                                                                                   */
  570. /* Decsription: window content definition procedure                                  */
  571. /*                                                                                   */
  572. /* Inputs:  none                                                                     */
  573. /*                                                                                   */
  574. /* Outputs: none                                                                     */
  575. /*                                                                                   */
  576. /* ********************************************************************************* */
  577.  
  578. MyDraw2()                                               /* window content definition procedure */   
  579.  
  580. {
  581.     int dbr;                                                /* data bank register value */
  582.     
  583.     dbr = SaveDB();                                         /* make the data bank reg. */
  584.                                                             /* point to globals, save it */
  585.     linetodraw = 0;
  586.                                                             /* all families, base & non-base */
  587.     ShowFont(FontToShow);                                   /* display font strike */
  588.     LoadSysFont();
  589.     ApErrorCheck(MyDraw2LoadSysFontErr);                    /* Is LoadSysFont OK? */
  590.     RestoreDB(dbr);                                         /* restore data bank reg. for return */
  591.                                                             /* to toolbox */
  592.     
  593. }
  594.  
  595.  
  596. /* ********************************************************************************* */
  597. /*                                                                                   */
  598. /* Procedure FontCheckMItem                                                          */
  599. /*                                                                                   */
  600. /* Decsription: This procedure checks specified font item in the menu bar and        */
  601. /*              unchecks previously checked item, if any                             */
  602. /*                                                                                   */
  603. /* Inputs:  pointer to FontID to be checked in menu bar,                             */
  604. /*          flag indicating whether previously checked item exists.                  */
  605. /*                                                                                   */
  606. /* Outputs: none                                                                     */
  607. /*                                                                                   */
  608. /* ********************************************************************************* */
  609.  
  610. FontCheckMItem(FontToCheck,uncheck)
  611. FontIDPtr FontToCheck;                                      /* pointer to FontID to be checked */
  612. int uncheck;                                                /* flag if prev checked item exists */
  613. {
  614.     int prevcheckedID;                                      /* menu id */
  615.     
  616.     prevcheckedID = checkedID;
  617.     if (uncheck = true) CheckMItem(false,prevcheckedID);        /* uncheck menu item */
  618.     checkedID = FamNum2ItemID(FontToCheck->fidRec.famNum);
  619.     CheckMItem(true,checkedID);                                 /* check menu item */
  620. }
  621.  
  622.  
  623. /* ********************************************************************************* */
  624. /*                                                                                   */
  625. /* Procedure AddApFont:                                                              */
  626. /*                                                                                   */
  627. /* Decsription: copies system font into application created font,                    */
  628. /*              generates unique name and number of font family                      */
  629. /*                                                                                   */
  630. /* Inputs:  none                                                                     */
  631. /*                                                                                   */
  632. /* Outputs: none                                                                     */
  633. /*                                                                                   */
  634. /* ********************************************************************************* */
  635.  
  636. AddApFont()
  637. {
  638.     #define FontFamNameOverflow 27  
  639.     #define UnusedFontFamNum 0x80
  640.     FontID MyFont,SelectFontID;                             /* fontIDs proper and long form */
  641.     char stritem1[26],stritem2[27];                         /* misc. strings and ptrs to strings */
  642.     ptr strptr1,strptr2;
  643.     char myApFontName[26],fontname[80];                     /* Font name strings */
  644.     ptr fontnameptr;                                        /* ptr to Font name string */
  645.     FontHndl MyApFontHndl,MySysFontHandle;                  /* Handles to font */
  646.     int *MyApFontPatchPtr;                                  /* ptr into font */
  647.     long MyApFontSize;                                      /* size of font */
  648.     int MyFontSpecBits,MyFamStatBits,MyFamSpecBits;         /* misc. Font Bits */
  649.     int MyApFamNum;                                         /* font family number */
  650.     int nthfontname,numsuffixplaces,numleadingspaces;       /* used to create unique font name */
  651.     FontStatRec MyFontStatRec;                              /* Font status record and StatRecPtr */
  652.     FontStatRecPtr MyFontStatRecPtr;
  653.         
  654.     strptr1 = &stritem2[0];
  655.     strptr1 = &stritem2[0];
  656.     strcpy(stritem1,"                          ");
  657.     strcpy(myApFontName,"ApFont");
  658.     
  659.     MyFont.fidLong = FMGetCurFID();                         /* install 16 point version of font */
  660.     
  661.     MyFont.fidRec.fontSize = 16;
  662.     InstallFont(MyFont,ScalingOn);                          /* install */
  663.     ApErrorCheck(ApFontInstallFontErr1);                    /* Is InstallFont OK? */
  664.     
  665.     MySysFontHandle = GetFont();                            /* prepare to duplicate the font */
  666.     MyApFontSize = GetHandleSize(MySysFontHandle);          /* determine size of font */
  667.                                                             /* make room for duplicate */
  668.     MyApFontHndl = (FontHndl) NewHandle(MyApFontSize,MyID,0,0L);    /* make room for duplicate */
  669.     HLock(MyApFontHndl);
  670.     ApErrorCheck(ApFontNewHandleErr);                       /* Is NewHandle OK? */
  671.     
  672.     if (_toolErr == 0) {
  673.     
  674.             HandToHand(MySysFontHandle,(Handle) MyApFontHndl,MyApFontSize);
  675.             MyApFamNum = 0xfffe;                    /* prepare to validate font number not used */
  676.             while ((GetFamInfo(MyApFamNum,strptr1) & notFoundBit) != notFoundBit) --MyApFamNum;
  677.             myApFontNamePtr = &myApFontName[0];     /* prepare to validate font name not used */
  678.             strcpy(stritem1,myApFontName);          /* init temp font name */ 
  679.             nthfontname = 0;                        /* may be used to suffix font name */
  680.                                                     /* loop until illegal or exhausted */
  681.     while ((GetFamNum(strptr1) != IllegalFontFamNum) & (strlen(stritem1) !=FontFamNameOverflow)) {
  682.                     ++nthfontname;                                  /* bump the suffix value */
  683.                     numsuffixplaces = (int) log10(nthfontname) + 1; /* calc # digits in suffix */
  684.                                                                     /* make a string of suffix */
  685.                     Int2Dec(nthfontname,strptr2,numsuffixplaces,true);
  686.                     stritem2[numsuffixplaces]= '\0';                /* terminate suffix string */
  687.                     strcpy(stritem1,myApFontName);                  /* reinit temp font name */
  688.                     strcat(strptr1,strptr2);                        /* append suffix */
  689.             }
  690.             c2pstr(myApFontNamePtr);
  691.             AddFamily(MyApFamNum,myApFontNamePtr);
  692.             ApErrorCheck(ApFontAddFamilyErr);                       /* Is AddFamily OK? */
  693.  
  694.                                                     /* patch the font # of the font record */
  695.             MyApFontPatchPtr =  (int *) (((char *) *MyApFontHndl) + 2);
  696.             *MyApFontPatchPtr = MyApFamNum;
  697.             AddFontVar(MyApFontHndl,0);
  698.             ApErrorCheck(ApFontAddFontVarErr);                      /* Is AddFontVar OK? */
  699.             HUnlock(MyApFontHndl);
  700.             MyFont.fidRec.famNum = MyApFamNum;
  701.             InstallFont(MyFont,ScalingOn);
  702.             ApErrorCheck(ApFontInstallFontErr2);    /* Is InstallFont OK? */
  703.     }
  704. }
  705.  
  706.  
  707. /* ********************************************************************************* */
  708. /*                                                                                   */
  709. /* Procedure InventoryFonts:                                                         */
  710. /*                                                                                   */
  711. /* Decsription: produces font catalog consisting of number of families               */
  712. /*              (base & non-base), generates unique name and number of font family.  */
  713. /*              assumes LoadFont and FindFontStats group fonts by size in increasing */
  714. /*              order within each family and by style in increasing order within     */
  715. /*              each size. If fonts are to be loaded, they are also set to be        */
  716. /*              purgeable.                                                           */
  717. /*                                                                                   */
  718. /* Inputs:  flag whether to load fonts as they are being inventoried                 */
  719. /*                                                                                   */
  720. /* Outputs: none                                                                     */
  721. /*                                                                                   */
  722. /* ********************************************************************************* */
  723.  
  724. InventoryFonts(loadthefonts)
  725. int loadthefonts;
  726.  
  727. {
  728.     FontID MyFont,SelectFontID;                             /* fontIDs proper and long form */
  729.     char stritem1[26],stritem2[27];                 /* misc. strings and ptrs to strings */
  730.     ptr strptr1,strptr2;
  731.     char fontname[80];
  732.     ptr fontnameptr;
  733.                                                             /* used to loop through fonts*/
  734.     int eachfamavail,numfontsinfam,eachfontinfam,eachfontavail;
  735.     int cursize,numsizesinfont,numstylesinsize;             /* used to loop through fonts */
  736.                                                             /* misc. font values*/
  737.     int MyFontSpecBits,MyOtherFontSpecBits,MyFamStatBits,MyFamSpecBits; 
  738.     FontStatRec MyFontStatRec;                              /* Font status record and StatRecPtr */
  739.     FontStatRecPtr MyFontStatRecPtr;
  740.     
  741.     strptr1 = &stritem1[0];
  742.     strptr2 = &stritem2[0];
  743.     
  744.     
  745.     LoadSysFont();
  746.     ApErrorCheck(InvFontLoadSysFontErr);                        /* Is LoadSysFont OK? */
  747.     
  748.     MyFamSpecBits = 0;
  749.     FontsAvail.numFamsAvail = CountFamilies(MyFamSpecBits);     /* determine no. of families */
  750.     MyFontSpecBits = realOnlyBit | anyFamBit | anyStyleBit | anySizeBit;   /* all real fonts */
  751.     SelectFontID.fidRec.famNum = 0;
  752.     SelectFontID.fidRec.fontStyle = 0xff;                               /* (any style) */
  753.     SelectFontID.fidRec.fontSize = 1;
  754.     FontsAvail.numFontsAvail = CountFonts(SelectFontID,MyFontSpecBits); /* determine # of fonts */
  755.     eachfamavail = 0;                                           /* init family counter */
  756.     eachfontavail = 0;                                          /* init font counter */
  757.     fontnameptr = &fontname[0];                                 /* set up ptr to font name string*/
  758.     MyFontSpecBits = realOnlyBit | anyStyleBit | anySizeBit;    /* all real fonts in each family */
  759.     do {                                                        /*loop through font family list */
  760.             ++eachfamavail;                                     /* increment family counter */
  761.                                                             /* determine number of nth family */
  762.             SelectFontID.fidRec.famNum = FindFamily(MyFamSpecBits,eachfamavail,fontnameptr);
  763.                                                         /* determine # fonts in that family */
  764.             numfontsinfam = CountFonts(SelectFontID,MyFontSpecBits);
  765.             eachfontinfam = 0;                          /* init fonts in family counter */
  766.             numsizesinfont = 0;                         /* init sizes in family counter */
  767.             cursize = 0;                                /* init current size */
  768.             do {                                        /* loop through the fonts in this family */
  769.                                                         /* increment fonts in family counter */
  770.                     ++eachfontinfam;
  771.                                                         /* set pointer to nth font status record */
  772.                     MyFontStatRecPtr = &FontsAvail.FontStatRecTable[eachfontavail];
  773.                     switch(loadthefonts) {
  774.                         case loadfonts:
  775.                           /* assume LoadFont and FindFontStats group fonts by size in increasing */
  776.                           /* order within each family and by style in increasing order within    */
  777.                           /* each size */
  778.                           
  779.                           /* there was a bug in the status record returned by LoadFont prior to */
  780.                           /* GS/OS, substitute FindFontStats,InstallFont */
  781.                           /* in place of LoadFont if and when running under pre-GS/OS system */
  782.                           /* to return correct status record */
  783.                                                                     
  784.                           /* make current and */
  785.                           /* determine stats of nth font in family */
  786.                             LoadFont(SelectFontID,MyFontSpecBits,eachfontinfam,MyFontStatRecPtr);
  787.                             ApErrorCheck(InvFontLoadFontErr);   /* Is InstallFont OK? */
  788.                         
  789.                           /* prepare to set purge bit, at discretion of application */
  790.                           /* check first that not attempting to set purge bit of system font */
  791.                             if (MyFontStatRecPtr->resultID.fidRec != curSysID.fidRec)
  792.                             MyFontStatRecPtr->resultStats = 
  793.                                 MyFontStatRecPtr->resultStats | purgeBit;
  794.         
  795.                           /* set purge bit */
  796.                           /* !!!! */
  797.                           /* When fonts are to be marked purgeable using SetPurgeStat, the id of */
  798.                           /* the font to purge should be that returned from a font manager call, */
  799.                           /* such as FMGetCurFID, FindFontStats, or LoadFont. */
  800.  
  801.                             SetPurgeStat(MyFontStatRecPtr->resultID,MyFontStatRecPtr->resultStats);
  802.                                                                 /* Is SetPurgeStat OK? */
  803.                             ApErrorCheck(InvFontSetPurgeStatErr);
  804.                             break;
  805.                         
  806.                         case dontloadfonts:
  807.                                                         /* determine stats of nth font in family */
  808.                          FindFontStats(SelectFontID,MyFontSpecBits,eachfontinfam,MyFontStatRecPtr);
  809.                          break;
  810.                             
  811.                         default:
  812.                             /*error */
  813.                             break;
  814.                     }
  815.                         
  816.                                                     /* does the font size equal previous font? */
  817.                     if (MyFontStatRecPtr->resultID.fidRec.fontSize != cursize)
  818.                     {
  819.                         ++numsizesinfont;           /* no- then increment number of sizes/family*/
  820.                         numstylesinsize = 0;        /*     and set to zero number of styles/size*/
  821.                     }
  822.                                                     /* store current font size for comparison */
  823.                     cursize = MyFontStatRecPtr->resultID.fidRec.fontSize;
  824.                     ++numstylesinsize;              /* increment number of styles/size */
  825.                     ++eachfontavail;                /* increment fonts counter */
  826.             }
  827.             while (eachfontinfam < numfontsinfam);
  828.     }
  829.     while (eachfamavail < FontsAvail.numFamsAvail);
  830. }
  831.  
  832.  
  833. /* ********************************************************************************* */
  834. /*                                                                                   */
  835. /* Procedure FindAltSysFont                                                          */
  836. /*                                                                                   */
  837. /* Decsription: resets system font to first other font cataloged with same size      */
  838. /*                                                                                   */
  839. /* Inputs:  none                                                                     */
  840. /*                                                                                   */
  841. /* Outputs: none                                                                     */
  842. /*                                                                                   */
  843. /* ********************************************************************************* */
  844.  
  845. FindAltSysFont()
  846. {
  847.     int cursize,eachfontavail;              /* loop variables */
  848.     FontStatRecPtr MyFontStatRecPtr;        /* points to font status record */
  849.     
  850.     cursize = curSysID.fidRec.fontSize;
  851.     eachfontavail = 0;                          /* init font counter */
  852.     do {                                        /* loop through the font catalog */
  853.                                                 /* set pointer to nth font status record */
  854.         MyFontStatRecPtr = &FontsAvail.FontStatRecTable[eachfontavail];
  855.         ++eachfontavail;
  856.     }
  857.     while ((eachfontavail<FontsAvail.numFontsAvail) && 
  858.     ((MyFontStatRecPtr->resultID.fidRec.fontSize != cursize) || 
  859.      (MyFontStatRecPtr->resultID ==curSysID)));
  860.           
  861.                                         /* change system font if found other font of same size */
  862.     if ((MyFontStatRecPtr->resultID != curSysID) &&
  863.         (MyFontStatRecPtr->resultID.fidRec.fontSize == cursize)) {
  864.         FMSetSysFont(MyFontStatRecPtr->resultID);
  865.                                                 /* Is FMSetSysFontErr OK? */
  866.         ApErrorCheck(FindAltSysFontFMSetSysFontErr);
  867.         curSysID.fidLong = FMGetSysFID();
  868.     }
  869. }
  870.  
  871.  
  872. /* ********************************************************************************* */
  873. /*                                                                                   */
  874. /* Procedure DispNewFont:                                                            */
  875. /*                                                                                   */
  876. /* Decsription: resizes window data and forces redisplay of window contents          */
  877. /*                                                                                   */
  878. /* Inputs:  none                                                                     */
  879. /*                                                                                   */
  880. /* Outputs: none                                                                     */
  881. /*                                                                                   */
  882. /* ********************************************************************************* */
  883.  
  884. DispNewFont()
  885. {
  886.     int drawheight;
  887.  
  888.     InstallFont(FontToShow,ScalingOn);
  889.     ApErrorCheck(DispNewFontInstallFontErr);                    /* Is InstallFont OK? */
  890.     CurrHeight = CalcLineHeight();                              /* calc # pixels between lines */
  891.     drawheight = 40 + (13*CurrHeight) + 20;
  892.     SetDataSize(ScreenWidth,drawheight,StrikeWindow);
  893.     SetPort(StrikeWindow);                                      /* insure correct port */
  894.     EraseRect(&(*StrikeWindow).portRect);                       /* erase the port */
  895.     InvalRect(&(*StrikeWindow).portRect);                       /* and cause it to be redrawn */
  896. }
  897.  
  898.  
  899. /* ********************************************************************************* */
  900. /*                                                                                   */
  901. /* Procedure MenuFontSelect:                                                         */
  902. /*                                                                                   */
  903. /* Decsription: checks the item in menu bar and initiates display of font strike     */
  904. /*                                                                                   */
  905. /* Inputs:  user selected font menu item                                             */
  906. /*                                                                                   */
  907. /* Outputs: none                                                                     */
  908. /*                                                                                   */
  909. /* ********************************************************************************* */
  910.  
  911. MenuFontSelect()
  912. {
  913.     int theMenuID;                                  /* gets user selected font menu item */
  914.     
  915.     theMenuID = (int) (EventRec.wmTaskData);                /* pick up menuID */
  916.                                                             /* determine font ID */
  917.     FontToShow.fidRec.famNum = ItemID2FamNum(theMenuID);    /* determine family # */
  918.     FontToShow.fidRec.fontSize = ChosenSize;                /* set pt. font */
  919.     FontToShow.fidRec.fontStyle = ChosenStyle;              /* set style    */
  920.     FontCheckMItem(&FontToShow,douncheck);                  /* check font in menu */
  921.     DispNewFont();                                          /* display font strike */                                                       
  922. }
  923.  
  924.  
  925. /* ********************************************************************************* */
  926. /*                                                                                   */
  927. /* Procedure MenuFontChoose:                                                         */
  928. /*                                                                                   */
  929. /* Decsription: Invokes choose font dialog, checks the user specified item in        */
  930. /*              menu bar, and initiates display of font strike                       */
  931. /*                                                                                   */
  932. /* Inputs:  user selection of 'choose' from font menu                                */
  933. /*                                                                                   */
  934. /* Outputs: none                                                                     */
  935. /*                                                                                   */
  936. /* ********************************************************************************* */
  937.  
  938. MenuFontChoose()
  939. {
  940. GrafPortPtr preserveport;
  941.  
  942.     preserveport = GetPort();
  943.     SetPort(StrikeWindow);                      /* operate on strike port */
  944.     
  945.     ChosenFont.fidLong = ChooseFont(FontToShow,0);      /* user font choice */
  946.     ApErrorCheck(MenuFontChooseErr);                    /* Is ChooseFont OK? */
  947.     if (ChosenFont.fidLong != 0L) {
  948.         FontToShow.fidLong = ChosenFont.fidLong;
  949.         ChosenSize = FontToShow.fidRec.fontSize;                /* store font size chosen */
  950.         ChosenStyle = FontToShow.fidRec.fontStyle;              /* store font style chosen */
  951.         FontCheckMItem(&FontToShow,douncheck);          /* check font in menu */
  952.         DispNewFont();                                  /* display font strike */                               
  953.         }
  954.     
  955.     SetPort(preserveport);                      /* restore port */
  956.  
  957. }
  958.  
  959.  
  960. /* ************************************************************************* */
  961. /*                                                                           */
  962. /* Procedure OpenCatalogWindow                                               */
  963. /*                                                                           */
  964. /* Decsription: This routine creates and shows the catalog window and        */
  965. /*              disables the menu item for opening the catalog window        */
  966. /*                                                                           */
  967. /* ************************************************************************* */
  968.  
  969. OpenCatalogWindow()
  970. {
  971.  
  972.     CatalogWindow = NewWindow2(NULL, NULL, MyDraw, NULL, 2,
  973.         CatalogWindowID, rWindParam1);                              /* create and show window */
  974.     SetPort(CatalogWindow);
  975.     ShowWindow(CatalogWindow);
  976.     DisableMItem(OpenCatWindowID);                                  /* disable menu item */
  977. }
  978.  
  979.  
  980. /* ************************************************************************* */
  981. /*                                                                           */
  982. /* Procedure OpenStrikeWindow                                                */
  983. /*                                                                           */
  984. /* Decsription: This routine creates and shows the font strike  window and   */
  985. /*              disables the menu item for opening the font strike window    */
  986. /*                                                                           */
  987. /* ************************************************************************* */
  988.  
  989. OpenStrikeWindow()
  990. {
  991.  
  992.     StrikeWindow = NewWindow2(NULL, NULL, MyDraw2, NULL, 2,
  993.         StrikeWindowID, rWindParam1);                               /* create and show window */
  994.     SetPort(StrikeWindow);
  995.     ShowWindow(StrikeWindow);
  996.     SetMenuFlag(enableMenu,FontMenuID);                             /* enable the font menu */
  997.     HiliteMenu(FALSE,FontMenuID);                                   /* force it (only) to redraw */
  998.     DisableMItem(OpenStrikeWindowID);                               /* disable menu item */
  999. }
  1000.  
  1001.  
  1002. /* ************************************************************************* */
  1003. /*                                                                           */
  1004. /* InitApp - This routine is called once after the tools are started. This   */
  1005. /* is where you would create your menus, and other objects your program will */
  1006. /* need at the very start.                                                   */
  1007. /*                                                                           */
  1008. /* ************************************************************************* */
  1009.  
  1010. InitApp()
  1011. {
  1012.     FontID MyFont;                                  /* fontID proper and long form */
  1013.     int menuheight;                                 /* height of menu bar */
  1014.     int maxfontmitems;                              /* max # of fonts to list in menu */
  1015.     int menuversioncheck;                           /* menu version less prototype bit */
  1016.     int i;                                          /* loop variable */
  1017.  
  1018.     WaitCursor();                                           /* inventory make take a while */
  1019.     ShowCursor();
  1020.     QuitFlag = 0;
  1021.     curSysID.fidLong = FMGetSysFID();                       /* find and store the system fontID */
  1022.     AddApFont();
  1023.     InventoryFonts(loadfonts);
  1024.     FindAltSysFont();                                       /* make sys font any other 8 pt. font*/
  1025.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  1026.     SetMenuBar(NULL);
  1027.     
  1028.     FixAppleMenu(AppleMenuID);                              /* Add DAs to apple menu     */
  1029.     MyFamSpecBits = 0;
  1030.                                                             /* append fonts to menu if */
  1031.                                                             /* they'll fit, assume sys font */
  1032.                                                             /* is 8 pt. font */
  1033.     menuheight = FixMenuBar();
  1034.     maxfontmitems = (int) ((200 - 2*menuheight) / menuheight);  
  1035.     menuversioncheck = MenuVersion() & 0x7fff;                      /* strip the prototype bit */
  1036.     if ((FontsAvail.numFamsAvail <= maxfontmitems) || menuversioncheck >= 0x300)
  1037.         FixFontMenu(FontMenuID,ChooseID+1,MyFamSpecBits);               /* put fonts in font menu */
  1038.     CalcMenuSize(0,0,FontMenuID);                                   /* reset size of font menu */
  1039.     numFontMenuItems = CountMItems(FontMenuID);                     /* used to handle font menu */
  1040.                                                                     /* choices in DoMenuSelect */
  1041.     FontToShow.fidLong = FMGetSysFID();                             /* get system font id */
  1042.     FontCheckMItem(&FontToShow,omituncheck);                        /* check font in menu */                        
  1043.     ChosenSize = FontToShow.fidRec.fontSize;                        /* store font size chosen */
  1044.     ChosenStyle = FontToShow.fidRec.fontStyle;                      /* store font style chosen */
  1045.  
  1046.     DrawMenuBar();
  1047.     
  1048.     OpenCatalogWindow();                                    /* create and show windows, */
  1049.     OpenStrikeWindow();                                     /* disable open window menu choices */
  1050.     SetPort(CatalogWindow);
  1051.     DispNewFont();                                                  /* display font strike */                                                   
  1052.     
  1053.     InitCursor();                                                   /* restore cursor to normal */
  1054.     
  1055. }
  1056.  
  1057.  
  1058. /* ************************************************************************* */
  1059. /*                                                                           */
  1060. /* InGoAway - This routine gets called when the user clicks in the go away   */
  1061. /* box of a window.                                                          */
  1062. /*                                                                           */
  1063. /* ************************************************************************* */
  1064.  
  1065. InGoAway()
  1066. {
  1067.     GrafPortPtr windowtoclose;
  1068.     
  1069.     windowtoclose = (GrafPortPtr) EventRec.wmTaskData;          /* close the window  */
  1070.     CloseWindow(windowtoclose);
  1071.     if (windowtoclose == CatalogWindow)                         /* enable open window menu opt. */
  1072.         EnableMItem(OpenCatWindowID);
  1073.     else if (windowtoclose == StrikeWindow) {
  1074.             SetMenuFlag(disableMenu,FontMenuID);                /* disable the font menu */
  1075.             HiliteMenu(FALSE,FontMenuID);                       /* force it (only) to redraw */
  1076.             EnableMItem(OpenStrikeWindowID);
  1077.          }
  1078.  
  1079. }
  1080.  
  1081.  
  1082. /* ************************************************************************* */
  1083. /*                                                                           */
  1084. /* Ignore - called when an event occurs that you don't want/need to handle   */
  1085. /*                                                                           */
  1086. /* ************************************************************************* */
  1087.  
  1088. Ignore()
  1089. {
  1090.     /* Does nothing */
  1091. }
  1092.  
  1093.  
  1094. /* ************************************************************************* */
  1095. /*                                                                           */
  1096. /* DoAbout - Show the vanity box until the OK button is hit. Calls           */
  1097. /* NoteAlert to display a dialog box with an icon and handle mouse clicks.   */
  1098. /*                                                                           */
  1099. /* ************************************************************************* */
  1100.  
  1101. DoAbout()
  1102. {
  1103.     AlertWindow(4,NULL, 0x0001L);
  1104. }
  1105.  
  1106.  
  1107. /* ************************************************************************* */
  1108. /*                                                                           */
  1109. /* DoUpdate - This routine is called if you have a window and the Event      */
  1110. /* Manager notices that it needs to have some or all of it redrawn.          */
  1111. /*                                                                           */
  1112. /* ************************************************************************* */
  1113.  
  1114. DoUpdate()
  1115.     /* no update */
  1116.  
  1117.  
  1118. /* ************************************************************************* */
  1119. /*                                                                           */
  1120. /* DoQuit - Set the quit flag. This tells the Event loop to exit.            */
  1121. /*                                                                           */
  1122. /* ************************************************************************* */
  1123.  
  1124. DoQuit()
  1125. {
  1126.     QuitFlag = -1;
  1127. }
  1128.  
  1129.  
  1130. DoMenuSelect()
  1131. {
  1132.     /* Procedure to handle all menu selections.  Examines the event.TaskData
  1133.     ** menu item ID word from TaskMaster (from Event Manager) and calls the
  1134.     ** appropriate routine.  While the routine is running the menu title is
  1135.     ** still highlighted.  After the routine returns, we unhilight the
  1136.     ** menu title.
  1137.     */
  1138.     
  1139.     unsigned int    menuNum, itemNum;
  1140.  
  1141.     menuNum = HiWord(EventRec.wmTaskData);
  1142.     itemNum = LoWord(EventRec.wmTaskData);
  1143.  
  1144.                                                                     /* font menu font selection? */
  1145.     if ((itemNum > ChooseID) && (itemNum <= (ChooseID+numFontMenuItems)))
  1146.         MenuFontSelect();                                           /* yes- call this routine */
  1147.     else {
  1148.         switch (itemNum) {
  1149.             case AboutID:
  1150.                 DoAbout();
  1151.                 break;
  1152.             case OpenCatWindowID:
  1153.                 OpenCatalogWindow();
  1154.                 break;
  1155.             case OpenStrikeWindowID:
  1156.                 OpenStrikeWindow();
  1157.                 break;
  1158.             case QuitID:
  1159.                 DoQuit();
  1160.                 break;
  1161.             case ChooseID:
  1162.                 MenuFontChoose();
  1163.                 break;
  1164.         }
  1165.     }
  1166.     HiliteMenu(0, menuNum);     /* Unhighlight the menu title. */
  1167. }
  1168.  
  1169.  
  1170.  
  1171. /* ************************************************************************* */
  1172. /*                                                                           */
  1173. /* EventLoop - This routine is the heart of your application. It is repeat-  */
  1174. /* edly called and when the user selects/operates something, it dispatches   */
  1175. /* to a routine to do the proper thing.                                      */
  1176. /*                                                                           */
  1177. /* ************************************************************************* */
  1178.  
  1179. EventLoop()
  1180. {
  1181.     word theTask;
  1182.     
  1183.     do {
  1184.     theTask = TaskMaster(everyEvent,&EventRec); /* Get an event from TaskMaster */
  1185.     switch (theTask) {                          /* switch on the event type. */
  1186.         case updateEvt:                         /* Handle updates. */
  1187.             DoUpdate();
  1188.             break; 
  1189.         case wInMenuBar:                        /* Handle selections in Special */
  1190.         case wInSpecial:                        /* and normal menu item selects */
  1191.             DoMenuSelect();
  1192.             break;
  1193.         case wInGoAway:                         /* Handle a click in the go away box */
  1194.             InGoAway();
  1195.             break;
  1196.         }
  1197.     } while (QuitFlag == 0);                    /* Loop until "Quit" is selected */
  1198. }
  1199.